package com.ruoyi.web.controller.mixuebingcheng;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mixuebingcheng.domain.vo.ViewCouponVo;
import com.ruoyi.mixuebingcheng.domain.bo.ViewCouponBo;
import com.ruoyi.mixuebingcheng.service.IViewCouponService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * VIEW
 *
 * @author ruoyi
 * @date 2023-10-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mixuebingcheng/viewCoupon")
public class ViewCouponController extends BaseController {

    private final IViewCouponService iViewCouponService;

    /**
     * 查询VIEW列表
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:list")
    @GetMapping("/list")
    public TableDataInfo<ViewCouponVo> list(ViewCouponBo bo, PageQuery pageQuery) {
        return iViewCouponService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出VIEW列表
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:export")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ViewCouponBo bo, HttpServletResponse response) {
        List<ViewCouponVo> list = iViewCouponService.queryList(bo);
        ExcelUtil.exportExcel(list, "VIEW", ViewCouponVo.class, response);
    }

    /**
     * 获取VIEW详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:query")
    @GetMapping("/{id}")
    public R<ViewCouponVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iViewCouponService.queryById(id));
    }

    /**
     * 新增VIEW
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:add")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ViewCouponBo bo) {
        return toAjax(iViewCouponService.insertByBo(bo));
    }

    /**
     * 修改VIEW
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:edit")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ViewCouponBo bo) {
        return toAjax(iViewCouponService.updateByBo(bo));
    }

    /**
     * 删除VIEW
     *
     * @param ids 主键串
     */
    @SaCheckPermission("mixuebingcheng:viewCoupon:remove")
    @Log(title = "VIEW", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iViewCouponService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
